package jmine.tec.sync.dao;

import jmine.tec.sync.domain.RemoteEntityReference;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import bancosys.tec.persist.dao.BaseDAO;
import bancosys.tec.persist.dao.BeanNotFoundException;

/**
 * @author takeshi
 */
public class RemoteEntityReferenceDAO extends BaseDAO<RemoteEntityReference> {

    /**
     * Procura as entidades por nome, id remoto e origem.
     * 
     * @param entityName {@link String}
     * @param remoteId {@link Long}
     * @param source {@link String}
     * @return {@link RemoteEntityReference}
     * @throws BeanNotFoundException se o bean nao for encontrado
     */
    @Deprecated
    public RemoteEntityReference findByEntityNameRemoteIdSource(String entityName, Long remoteId, String source)
            throws BeanNotFoundException {
        Criteria crit = this.createCriteria();
        crit.add(Restrictions.eq("remoteEntityName", entityName));
        crit.add(Restrictions.eq("remoteEntityId", remoteId));
        crit.add(Restrictions.eq("source", source));
        return this.executeSingleQuery(crit);
    }

    /**
     * Procura as entidades por nome local, nome remoto, id remoto e origem.
     * 
     * @param localEntityName {@link String}
     * @param entityName {@link String}
     * @param remoteId {@link Long}
     * @param source {@link String}
     * @return {@link RemoteEntityReference}
     * @throws BeanNotFoundException se o bean nao for encontrado
     */
    public RemoteEntityReference findByEntityNameRemoteIdSource(String localEntityName, String entityName, Long remoteId, String source)
            throws BeanNotFoundException {
        Criteria crit = this.createCriteria();
        crit.add(Restrictions.eq("localEntityName", localEntityName));
        crit.add(Restrictions.eq("remoteEntityName", entityName));
        crit.add(Restrictions.eq("remoteEntityId", remoteId));
        crit.add(Restrictions.eq("source", source));
        return this.executeSingleQuery(crit);
    }
}